package com.lynn.salary.web.remote;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;

import com.lynn.salary.entity.User_;
import com.lynn.salary.pojo.LoginUser;
import com.lynn.salary.service.IUserService;
import com.lynn.salary.util.ObjectFactory;

public class RemoteService {
	public static Map<String,Object> cache = new HashMap<String,Object>();
	private IUserService userService = (IUserService) ObjectFactory.getBean("userService");
	public String monthReport(String flag,String type,String time,String st,String et,String[] eds) {
		cache.put(flag, new Object[]{type,time,st,et,eds});
		return flag;
	}
	
	public String tj1(String flag,String [] deps, String [] kqTypes,String time,String st,String et ) {
		cache.put(flag, new Object[]{deps,kqTypes,time,st,et});
		return flag;
	}
	
	public static RemoteService getInstance() {
		return new RemoteService();
	}
	
	public String frontEndLogin(String name,String pwd) {
		
		String id = name;
		String password = pwd;
		String errorMsg = "";
		System.out.println("dwr => 用户名:" + id + "\n密码:" + password);

		User_ u;
		try {
			u = userService.checkLoginUser(id, password);
		} catch (Exception e) {
			return "系统错误";
		}
		if (u == null) {
			errorMsg = "*请正确填写用户名或密码";
			return errorMsg;
		}
		if(u.getTag()!= null && u.getTag().contains(User_.FORBIDDEN)) {
			errorMsg = "*您的帐户已被管理员禁用";
			return errorMsg;
		}

		LoginUser loginUser = new LoginUser();
		loginUser.setLoginUser(u);
		WebContext ctx = WebContextFactory.get();
		HttpSession session = ctx.getSession();
		session.putValue("frontEndLoginUser", loginUser);
		
		return "success";
	}
}
